package com.dailywork.basepro.thread.conditionvar;

public class ConditionVar {

    public static void main(String[] args) {
        Bank bank = new Bank(2, 1000);
        ThreadExecptionHandler threadExecptionHandler = new ThreadExecptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(threadExecptionHandler);
        Thread thread1 =
                new Thread(
                        () -> {
                            try {
                                bank.transfer(0, 1, 500);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        },
                        "Thread1");
        Thread thread2 =
                new Thread(
                        () -> {
                            try {
                                bank.transfer(0, 1, 1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        },
                        "Thread2");

        Thread thread3 =
                new Thread(
                        () -> {
                            try {
                                Thread.sleep(1000000);
                                bank.transfer(1, 0, 1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        },
                        "Thread3");
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
